<?php

declare (strict_types=1);

namespace App\Models\GameDB\Frag;

use Illuminate\Database\Eloquent\Model;

class PoolTemplate extends Model
{
    protected $connection = 'mysql_game';
    protected $table = 'lottery_frag_pool_template';
    //protected $fillable = [];
    protected $guarded = [];
    //protected $casts = ['id' => 'int', 'user_id' => 'integer', 'amount' => 'integer', 'balance' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime'];

    public function one(array $filters)
    {
        return $this->where($filters)->first();
    }

    public function listAll(array $filters, $fields)
    {
        return self::query()->where($filters)->select($fields)->get();
    }

    public function sumTemplateCount(array $filters)
    {
        return self::query()->where($filters)->sum('count');
    }

    public function getGiftTemplateList(array $filters, array $fields)
    {
        return self::query()->where($filters)
            ->select($fields)
            ->join(app('model_frag_gift_template')->getTable(), 'gift_template_id', '=', app('model_frag_gift_template')->getTable() . ".id")
            ->where($filters)->get();
    }

}
